﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MahApps.Metro.Controls;
using GestorDocument.ViewModel.AsuntoTurno;

namespace GestorDocument.UI.AsuntoTurno
{
    /// <summary>
    /// Lógica de interacción para RechazarTurnoView.xaml
    /// </summary>
    public partial class RechazarTurnoView : MetroWindow
    {
        public RechazarTurnoView()
        {
            InitializeComponent();
            
            this.Loaded += delegate
            {
                Keyboard.Focus(this.txtComentarioRechazo);
            };
        }
        private TrancingAsuntoViewModel GetViewModel()
        {
            return this.DataContext as TrancingAsuntoViewModel;
        }

        private void btnCancelar_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnAgregar_Click(object sender, RoutedEventArgs e)
        {
            TrancingAsuntoViewModel viewModel = this.GetViewModel();

            viewModel.RechazarTurnoCommand.Execute(null);

            if (viewModel._Confirmation.Response)
            {
                this.Close();
            }
        }

        private void txtComentarioRechazo_GotFocus(object sender, RoutedEventArgs e)
        {
            if (sender == null) return;
            var box = sender as TextBox;

            if (box.IsFocused)
            {

                var oldFocus = FocusManager.GetFocusedElement(FocusManager.GetFocusScope(this));
                box.Select(box.Text.Length, 0);
                Keyboard.Focus(box); // or box.Focus(); both have the same results

            }
        }
    }
}
